﻿using Pdoxcl2Sharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using V3MainTool.Model;

namespace V3MainTool.UI
{
    /// <summary>
    /// UCProv.xaml 的交互逻辑
    /// </summary>
    public partial class UCProv : UserControl
    {
        string fold;
        List<StateFamily> list = new List<StateFamily>();
        List<string> fileList = new List<string>();
        public UCProv()
        {
            InitializeComponent();
            cmbType.Items.Add("西欧"); fileList.Add("00_west_europe.txt");
            cmbType.Items.Add("南欧"); fileList.Add("01_south_europe.txt");
            cmbType.Items.Add("东欧"); fileList.Add("02_east_europe.txt");
            cmbType.Items.Add("北非"); fileList.Add("03_north_africa.txt");
            cmbType.Items.Add("撒哈拉以南"); fileList.Add("04_subsaharan_africa.txt");
            cmbType.Items.Add("北美"); fileList.Add("05_north_america.txt");
            cmbType.Items.Add("中美"); fileList.Add("06_central_america.txt");
            cmbType.Items.Add("南美"); fileList.Add("07_south_america.txt");
            cmbType.Items.Add("中东"); fileList.Add("08_middle_east.txt");
            cmbType.Items.Add("中亚"); fileList.Add("09_central_asia.txt");
            cmbType.Items.Add("印度"); fileList.Add("10_india.txt");
            cmbType.Items.Add("东亚"); fileList.Add("11_east_asia.txt");
            cmbType.Items.Add("印尼"); fileList.Add("12_indonesia.txt");
            cmbType.Items.Add("澳洲"); fileList.Add("13_australasia.txt");
            cmbType.Items.Add("西伯利亚"); fileList.Add("14_siberia.txt");
            cmbType.SelectedIndex = 0;
            cmbType.SelectionChanged += CmbType_SelectionChanged;
        }

        private void CmbType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            LoadSelectedList();
        }
        private void LoadSelectedList()
        {
            if (cmbType.SelectedIndex >= list.Count)
            {
                dgv.ItemsSource = null;
                return;
            }
            dgv.ItemsSource = list[cmbType.SelectedIndex].MyList;
        }
        private void btnReload_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                fold = MainWindow.Instance.GetFold();
                string mypath = fold + @"\map_data\state_regions\";
                LocalHelper.State = LocalHelper.GetDic(fold + @"\localization\simp_chinese\map\states_l_simp_chinese.yml");
                LocalHelper.Buildings = LocalHelper.GetDic(fold + @"\localization\simp_chinese\buildings_l_simp_chinese.yml");
                for (int i = 0; i < fileList.Count; i++)
                {
                    using (FileStream fs = new FileStream(mypath + fileList[i], FileMode.Open))
                    {
                        this.list.Add(ParadoxParser.Parse(fs, new StateFamily()));
                    }
                }
                LoadSelectedList();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }

        private void btnOpenFold_Click(object sender, RoutedEventArgs e)
        {
            fold = MainWindow.Instance.GetFold();
            System.Diagnostics.Process.Start("explorer.exe", fold + @"\map_data\state_regions\");
        }

        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("待开发");
        }
    }
}
